#include "stdafx.h"

//input
int input2D(struct material substance[], struct die2D die[], 
			struct plate2D *plate, double *airThick, double *dx)
{
	int k;
	//Plate
	k = 0;
	substance[k].id = 0; 
	sprintf(substance[k].name, "Plate - 22MnB5 Steel");
	substance[k].density = 7830;			//UNIT:kg/m^3
	substance[k].htc = 32;					//UNIT:W/(m*K)
	substance[k].sh = 650;					//UNIT:J/(kg*K)
	substance[k].initTemp = PLATE_INIT_TEMP;			//UNIT:K
	
	//Die Up
	k = 1;
	substance[k].id = 1;
	sprintf(substance[k].name, "Die Up - 5CrMnMo Steel");
	substance[k].density = 7500;
	substance[k].htc = 35.23;
	substance[k].sh = 678.5;
	substance[k].initTemp = AIR_INIT_TEMP;
		
	//Die Down
	k = 2;
	substance[k].id = 2;
	sprintf(substance[k].name, "Die Down - HT200 - w(C) = 3%");
	substance[k].density = 7570;
	substance[k].htc = 39.2;
	substance[k].sh = 470;
	substance[k].initTemp = AIR_INIT_TEMP;

	//Gas
	k = 3;
	substance[k].id = 3;
	sprintf(substance[k].name, "Gas - Air");
	substance[k].density = 1.205;
	substance[k].htc = 0.0259;
	substance[k].sh = 1005;
	substance[k].initTemp = AIR_INIT_TEMP;

	substance[0].both[0] = 0; substance[1].both[0] = 0; substance[2].both[0] = 0; substance[3].both[0] = 20000;
	substance[0].both[1] = 0; substance[1].both[1] = 0; substance[2].both[1] = 0; substance[3].both[1] = 20000;
	substance[0].both[2] = 0; substance[1].both[2] = 0; substance[2].both[2] = 0; substance[3].both[2] = 20000;
	substance[0].both[3] = 20000; substance[1].both[3] = 20000; substance[2].both[3] = 20000; substance[3].both[3] = 0;
	
	die[0].height = 0.02;
	die[0].width = 0.08;
	die[1].height = 0.03;
	die[1].width = 0.08;
		
	(*plate).height = 0.002;
	(*plate).width = 0.05;

	*dx = 0.0001;
	*airThick = 0.002;

	return 0;
}

//output
int output(double *grid, int row, int col, double time, int pointX, int pointY)
{
	char *filename = (char *)malloc(sizeof(char) * 256);
	sprintf(filename, "temp%.0lfms.txt", time * 1000);

	FILE *fp;
	if((fp = fopen(filename, "at")) == NULL)
	{
		printf("cannot open %s \n", filename);
		return 0;
	}
	else
	{
		printf("output time = %10.3f\t T = %10.3f\n", time, grid[pointX * col + pointY]);
		for(int i = 0; i < row; i++)              
		{
			for(int j = 0; j < col; j++)                      
				fprintf(fp, "%lf ", grid[i * col + j]);
			fprintf(fp, "\n");
		}
		fclose(fp);
	}

	return 0;
}

//output
int outputInt(int *grid, int row, int col, double time, int pointX, int pointY)
{
	char *filename = (char *)malloc(sizeof(char) * 256);
	sprintf(filename, "temp%.0lfms.txt", time * 1000);

	FILE *fp;
	if((fp = fopen(filename, "at")) == NULL)
	{
		printf("cannot open %s \n", filename);
		return 0;
	}
	else
	{
		printf("output time = %10.3f\t T = %10d\n", time, grid[pointX * col + pointY]);
		for(int i = 0; i < row; i++)              
		{
			for(int j = 0; j < col; j++)                      
				fprintf(fp, "%d ", grid[i * col + j]);
			fprintf(fp, "\n");
		}
		fclose(fp);
	}

	return 0;
}
